package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.*;
import com.sc.nft.admin.task.SandQywxNoticTask;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.DigitalCollectionProductInfo;
import com.sc.nft.entity.IntegralTask;
import com.sc.nft.entity.InviteProductTask;
import com.sc.nft.entity.InviteTask;
import com.sc.nft.entity.vo.AdminInviteTaskVO;
import com.sc.nft.entity.vo.IntegralTaskVO;
import com.sc.nft.entity.vo.InviteTaskProductDetailVO;
import com.sc.nft.entity.vo.InviteTaskProductVO;
import com.sc.nft.enums.MessageTopic;
import com.sc.nft.service.DigitalCollectionProductInfoService;
import com.sc.nft.service.IntegralTaskService;
import com.sc.nft.service.InviteProductTaskService;
import com.sc.nft.service.InviteTaskService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;
import java.util.List;

/**
 * 拉新控制器
 *
 * @author kancy
 * @since 2022-05-31 15:58:35
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/allTask")
@Api(tags="后台活动任务模块")
public class AllTaskController {
    private final InviteTaskService inviteTaskService;
    private final IntegralTaskService integralTaskService;
    private final InviteProductTaskService inviteProductTaskService;
    private final DigitalCollectionProductInfoService digitalCollectionProductInfoService;

    @PostMapping(value="/getIntegralTaskList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取积分任务列表",notes="获取积分任务列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<IntegralTaskVO>> getIntegralTaskList(){
        List list = new IntegralTask().selectAll();
        return Result.successColl(list,IntegralTaskVO.class);
    }
    @PostMapping(value="/updateIntegralTask", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改积分任务",notes="修改积分任务", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateIntegralTask(@Valid @RequestBody UpdateIntegralTaskRequest updateIntegralTaskRequest){
        integralTaskService.updateIntegralTask(updateIntegralTaskRequest.getId(),updateIntegralTaskRequest.getIntegralNum());
        return Result.success();
    }
    @PostMapping(value="/updateIntegralTaskIsEnable", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改积分任务上下架状态",notes="修改积分任务上下架状态", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateIntegralTaskIsEnable(@Valid @RequestBody IdRequest idRequest){
        integralTaskService.updateIntegralTaskIsEnable(idRequest.getId());
        return Result.success();
    }
    @PostMapping(value="/getInviteTaskList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取邀请任务列表",notes="获取邀请任务列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminInviteTaskVO>> getInviteTaskList(){
        List list = new InviteTask().selectAll();
        return Result.successColl(list, AdminInviteTaskVO.class);
    }
    @PostMapping(value="/addInviteTask", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加邀请任务",notes="添加邀请任务", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addInviteTask(@Valid @RequestBody AddInviteTaskRequest addInviteTaskRequest){
         InviteTask inviteTask=new InviteTask();
         inviteTask.setInviteForwardName(addInviteTaskRequest.getInviteForwardName());
         inviteTask.setInviteLaterName(addInviteTaskRequest.getInviteLaterName());
         inviteTask.setInvitateRewardName(addInviteTaskRequest.getAwardName());
         inviteTask.setInviteNum(addInviteTaskRequest.getInviteNum());
         inviteTask.setIsEnable(Boolean.FALSE);
         inviteTask.insert();
        return Result.success();
    }
    @PostMapping(value="/updateInviteTask", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改邀请任务",notes="修改邀请任务", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateInviteTask(@Valid @RequestBody UpdateInviteTaskRequest updateInviteTaskRequest){
        inviteTaskService.updateInviteTask(updateInviteTaskRequest.getId(),updateInviteTaskRequest.getInviteForwardName(),updateInviteTaskRequest.getInviteLaterName(),
                                          updateInviteTaskRequest.getAwardName(),updateInviteTaskRequest.getInviteNum());
        return Result.success();
    }
    @PostMapping(value="/updateInviteTaskIsEnable", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改邀请任务上下架状态",notes="修改邀请任务上下架状态", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateInviteTaskIsEnable(@Valid @RequestBody IdRequest idRequest){
        inviteTaskService.updateInviteTaskIsEnable(idRequest.getId());
        return Result.success();
    }
    @PostMapping(value="/getInviteTaskProductDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取邀请任务奖励详情",notes="获取邀请任务奖励详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<InviteTaskProductDetailVO>> getInviteTaskProductDetail(@Valid @RequestBody IdRequest idRequest){
        List<InviteProductTask> list=inviteProductTaskService.getInviteTaskProductDetail(idRequest.getId());
        return Result.successColl(list, InviteTaskProductDetailVO.class);
    }

    @PostMapping(value="/deleteInviteTaskProduct", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除邀请任务奖励",notes="删除邀请任务奖励", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteInviteTaskProduct(@Valid @RequestBody IdRequest idRequest){
        new InviteProductTask().deleteById(idRequest.getId());
        return Result.success();
    }

    @PostMapping(value="/inviteTaskProductList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "可添加的邀请任务奖励列表",notes="可添加的邀请任务奖励列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<InviteTaskProductVO>> inviteTaskProductList(){
       List<DigitalCollectionProductInfo>list = digitalCollectionProductInfoService.inviteTaskProductList();
        return Result.successColl(list,InviteTaskProductVO.class);
    }
    @PostMapping(value="/addInviteTaskProduct", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加邀请任务奖励",notes="添加邀请任务奖励", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addInviteTaskProduct(@Valid @RequestBody AddInviteTaskProductRequest addInviteTaskProductRequest){
        inviteProductTaskService.addInviteTaskProduct(addInviteTaskProductRequest.getInviteTaskId(),addInviteTaskProductRequest.getProductId(),
                addInviteTaskProductRequest.getTypeClassify(),addInviteTaskProductRequest.getFirstTitle(),addInviteTaskProductRequest.getNum());
        return Result.success();
    }


    private final SandQywxNoticTask sandQywxNoticTask;
    @PostMapping(value="/allSendMsg", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "发送每日推送",notes="发送每日推送", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)

    public Result allSendMsg() throws Exception {
        sandQywxNoticTask.allSend();
        return Result.success();
    }



}